package com.ssm.controller;

import com.ssm.pojo.Account;
import com.ssm.sevice.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {


    @Autowired
    private AccountService accountService;

    @RequestMapping("/findAll")
    public String findAll(Model model) {
        List<Account> all = accountService.findAll();
        model.addAttribute("list", all);
        return "list";

    }

    @RequestMapping("/save")
    public String findAll(Account account) {
        accountService.save(account);
        return "redirect:/findAll";


    }
    @RequestMapping("/delete")
    public String findAll(Integer id) {
        accountService.delete(id);
        return "redirect:/findAll";
    }


    @RequestMapping("/findById")
    public String findById(Integer id,Model model) {
        List<Account> account = accountService.findById(id);
        model.addAttribute("account",account);
        return "update";
    }


    @RequestMapping("/update")
    public String findById(Account account) {
       accountService.update(account);
        return "redirect:/findAll";
    }



    @RequestMapping("/deleteBatch")
    public String deleteBatch(Integer[] ids) {
  accountService.deleteBatch(ids);
        return "redirect:/findAll";
    }                                   //$.ajax({
                         // contentType;
                        //})
                        //content-type:application/json
                       //content-type:application/x-www-form-urlencoded

@ResponseBody
    @RequestMapping("/pages/{ids}")
    public String pages( @RequestBody Account account, @RequestParam(name = "ids",defaultValue = "10") Integer id,@PathVariable Integer ids) {
        System.out.println(id);
        return "xxx";
    }
}
